/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kbclient;

import java.util.List;
import javax.swing.*;
import net.java.dev.jaxb.array.StringArray;
        
/**
 *
 * @author Psychoray
 */
public class Controller implements java.awt.event.ActionListener {
    
    // Global variables
    Model model;
    View view;
    
    public Controller() {
                
        //model.downloadAllArticles();
        //model.downloadAllCategoriesInformation();
        //model.downloadAllCategoriesProblem();
        
        //showArticle(2);
    }
    
    /*
     * Adds the model
     */
    public void addModel(Model m) {
        this.model = m;
    }
    
    /*
     * Adds the view
     */
    public void addView(View v) {
        this.view = v;
        view.setVisible(true);
    }
    
    /*
     * Overrides the ActionListener implementation
     */
    @Override
    public void actionPerformed(java.awt.event.ActionEvent e){
        
        //uncomment to see what action happened at view

        System.out.println ("Controller: The " + e.getActionCommand() 
                + " button is clicked at " + new java.util.Date(e.getWhen())
                + " with e.paramString " + e.paramString() );
        //model.downloadAllArticles();
        
        if(e.getActionCommand().equals("Go"))
        {
            SearchButton(view.getSearchField(), false);
        }
    }
   
    
    private void SearchButton(String criteria, boolean kutmvc)
    {
        Object test[] = model.ModalSocketWriter(criteria, kutmvc).toArray();
        
        for(int i =0; i <  test.length; i++)
        {
             System.out.println(i);
             System.out.println(test[i].toString());     
             
             Object[] blaat = new Object[10];
                    
                    blaat[i] =  test[i];
        }
        
        int ajaja = 3;
    }
    
    /**
     * @param indexNumber the ID of the article to show
     * Show article in the GUI 
     */        

    

}

